package com.maolong.helloworld;

import com.rabbitmq.client.*;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class Producter {
    private static final String QUEUE_NAME = "hello";
    public static void main(String[] args) throws IOException, TimeoutException {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("182.92.151.172");
        factory.setUsername("maolong");
        factory.setPassword("123456");

        Connection connection = factory.newConnection();

        Channel channel = connection.createChannel();

        /**
         * 参数说明
         *  queueDeclare(String queue, boolean durable, boolean exclusive, boolean autoDelete,
         *                                  Map<String, Object> arguments)
         * queue 代表队列名称
         * durable 是否持久化
         * exclusive 是否独占，是否一个消费者监听一个队列
         * autoDelete 是否自动删除，是否自动删除。如果没有消费者consumer,
         * arguments 代表参数
         */
        channel.queueDeclare(QUEUE_NAME,false,false,false,null);

        System.out.println("[producter] send message to queue: " + QUEUE_NAME);

        String message = "hello world";
        for (int i=0;i<10;i++){
            channel.basicPublish("",QUEUE_NAME,null,message.getBytes());
        }
    }
}
